﻿<%@ WebHandler Language="C#" Class="bpmHandler" %>
using System;
using System.IO;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Net;
using ReportBusiness;
/**
 * Description: MES-BPM系统接口
 * Copyright (c): 通力凯顿（北京）系统集成有限公司
 * Author: zhunan
 * Date: 2023.5.10
 */

public class bpmHandler : IHttpHandler
{
    public bool IsReusable { get { return false; } }
    private uMESReportOracleDAL dal = new uMESReportOracleDAL();
    public void ProcessRequest(HttpContext context)
    {
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "getProblemType")
        {
            string sql = @" 
SELECT t.problemtype
FROM bo_eu_mes_problem_type t 
WHERE 1=1";

            if (context.Request.QueryString["id"] != null)
            {
                sql += string.Format(" AND t.id = '{0}'", context.Request.QueryString["id"].ToString());
            }

            DataTable dtResult = dal.GetDataTable(sql);
            var json = JsonConvert.SerializeObject(dtResult);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
        }

        //查询bpm暂存批次信息
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "getBpmContainerInfo")
        {
            Result r = new Result();
            if (context.Request.QueryString["createuser"] != null && context.Request.QueryString["createuser"].ToString() != "")
            {
                string createuser = context.Request.QueryString["createuser"].ToString();
                string sql = string.Format("SELECT * FROM bpm_containerinfo t WHERE t.createuser = '{0}'", createuser);
                DataTable dt = dal.GetDataTable(sql);
                foreach (DataColumn col in dt.Columns)
                {
                    col.ColumnName = col.ColumnName.ToLower();
                }
                r.data = dt;
                r.total = Convert.ToInt32(dt.Rows.Count);
                r.meta = new Result.Meta(200, "请求成功");
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
            else
            {
                r.data = null;
                r.total = Convert.ToInt32(0);
                r.meta = new Result.Meta(200, "请求成功");
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
        }

        //删除bpm暂存批次信息
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "deleteBpmContainerInfo")
        {
            Result r = new Result();
            if (context.Request.QueryString["createuser"] != null && context.Request.QueryString["createuser"].ToString() != "")
            {
                string createuser = context.Request.QueryString["createuser"].ToString();
                string sql = string.Format("DELETE bpm_containerinfo t WHERE t.createuser = '{0}'", createuser);
                int qty = dal.ExecuteSql(sql);
                r.data = null;
                r.total = Convert.ToInt32(qty);
                r.meta = new Result.Meta(200, "请求成功");
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
            else
            {
                r.data = null;
                r.total = Convert.ToInt32(0);
                r.meta = new Result.Meta(200, "请求成功");
                context.Response.Write(JsonConvert.SerializeObject(r));
            }
        }
    }
}